package com.example.mvpdemo.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.example.mvpdemo.net.NetLoadingDialog;

/***
 * 基类activity
 */
public class BaseActivity extends AppCompatActivity implements BaseView {

    /***
     * 加载dialog
     */
    private NetLoadingDialog mDialog;
    private Toast mToast;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initWidget();
    }

    private void initWidget() {
        if (mDialog == null) {
            mDialog = new NetLoadingDialog(this);
        }


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        dismissDialog();
    }

    /***
     * 显示dialog
     * @param text 显示内容
     * @param isClickCancle 点击是否取消
     */
    public void showDialog(String text, boolean isClickCancle) {
        if (mDialog != null) {
            mDialog.showDialog(text, isClickCancle);
        }
    }

    /***
     * 取消dialog
     */
    public void dismissDialog() {
        if (mDialog != null && mDialog.isShowing()) {
            mDialog.closeDialog();
        }
    }

    /***
     * 弹Toast
     * @param content
     */
    public void showToast(String content) {
        if (mToast == null) {
            mToast = Toast.makeText(getApplicationContext(),content,Toast.LENGTH_SHORT);
        }else{
            mToast.setText(content);
        }
        mToast.show();
    }

}
